package com.ms.demo.process;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @description: bean的后置处理器
 * bean的后置处理器会在生命周期的初始化前后添加额外的操作，需要实现BeanPostProcessor接口，且配置到IOC容器中，需要注意的是，bean后置处理器不是单独针对某一个bean生效，而是针对IOC容器中所有bean都会执行
 * @author: ms
 * @create: 2022-08-23 17:07
 */
public class MyBeanProcessor implements BeanPostProcessor {

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("spring-bean的生命周期: 3、bean对象初始化之前操作（由bean的后置处理器负责）;beanName:" + beanName);
        return bean;
    }

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("spring-bean的生命周期: 5、bean对象初始化之后操作（由bean的后置处理器负责）;beanName:" + beanName);
        return bean;
    }
}